package com.cloud.demo.login.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cloud.demo.common.result.BaseResult;
import com.cloud.demo.login.bean.dto.LoginByAccountDTO;
import com.cloud.demo.login.bean.dto.QueryAllAccountDTO;
import com.cloud.demo.login.bean.entity.AccountInfo;
import com.cloud.demo.login.bean.vo.TokenVo;
import com.cloud.demo.login.service.AccountInfoService;
import com.cloud.demo.login.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类说明
 *
 * @author szj
 * @date 2021/7/20
 */
@Slf4j
@RestController
@RequestMapping("/account")
@Api(value = "AccountInfoController")
public class AccountInfoController {
    @Resource
    private AccountInfoService accountInfoService;

    @RequestMapping(value = "create", method = RequestMethod.POST)
    @ApiOperation("创建账号")
    @ApiImplicitParams({@ApiImplicitParam(name = "loginByAccountDTO", value = "登录信息", required = true, dataType = "LoginByAccountDTO")})
    public BaseResult<Void> create(@RequestBody LoginByAccountDTO loginByAccountDTO) {
        accountInfoService.create(loginByAccountDTO);
        return new BaseResult<>(null);
    }

    @RequestMapping(value = "queryAll", method = RequestMethod.POST)
    @ApiOperation("分页查询所有")
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "查询参数", required = true, dataType = "QueryAllAccountDTO")})
    public BaseResult<IPage<AccountInfo>> queryAll(@RequestBody QueryAllAccountDTO query) {

        return new BaseResult<>(accountInfoService.queryAll(query));
    }

    @RequestMapping(value = "delete", method = RequestMethod.DELETE)
    @ApiOperation("删除账号")
    public BaseResult<Void> delete(@RequestParam("id") Integer id) {
        accountInfoService.delete(id);
        return new BaseResult<>(null);
    }

    @RequestMapping(value = "detail", method = RequestMethod.GET)
    @ApiOperation("查询指定账号")
    public BaseResult<AccountInfo> detail(@RequestParam("id") Integer id) {
        return new BaseResult<>(accountInfoService.detail(id));
    }
}
